package cn.edu.scau.cmi.wuzewei.comprehensive;

import cn.edu.scau.cmi.wuzewei.simpleFactoryMethod.PolicyProducer;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class SimpleFactoryMethodWindow {
	public void newWindow(Stage primaryStage) {
		
		Group group = new Group();
		
		Image image = new Image("resource/01.jpg");
		ImageView imageView = new ImageView(image);
		imageView.setFitWidth(300);
		imageView.setFitHeight(280);
		imageView.setX(10);
		imageView.setY(10);
		group.getChildren().add(imageView);
		
		Label label1 = new Label("姓名： 蔡徐坤         学号： 201666666666");
		label1.setLayoutX(360);
		label1.setLayoutY(50);
		group.getChildren().add(label1);

		Label label2 = new Label("请选择保险：");
		label2.setLayoutX(360);
		label2.setLayoutY(100);
		group.getChildren().add(label2);
		
		@SuppressWarnings({ "unchecked", "rawtypes" })
		ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList(
			"司机受伤", "汽车损坏", "人员伤亡", "综合情况")
		);
		cb.setLayoutX(450);
		cb.setLayoutY(100);
		cb.getSelectionModel().select(0);
		group.getChildren().add(cb);
		
		TextArea textArea = new TextArea();
		textArea.setLayoutX(10);
		textArea.setLayoutY(310);
		textArea.setMinWidth(650);
		textArea.setMinHeight(230);
		group.getChildren().add(textArea);
		
		Button button = new Button("显示保险信息");
		button.setLayoutX(450);
		button.setLayoutY(180);
		button.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				textArea.setText(PolicyProducer.getPolicyObj(cb.getSelectionModel().selectedIndexProperty().get()).getInsurInfo());
			}
		});
		group.getChildren().add(button);		
		
		Scene scene = new Scene(group);
		primaryStage.setTitle("实验三：简单工厂方法");
		primaryStage.setWidth(700);
		primaryStage.setHeight(600);
		primaryStage.setScene(scene);
		primaryStage.show();
	}
}
